//package com.gtw.common.resolver;
//
//import com.gtw.common.annotation.LoginUserSys;
//import com.gtw.modules.entity.SysUserEntity;
//import com.gtw.modules.sys.service.SysUserService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.MethodParameter;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.support.WebDataBinderFactory;
//import org.springframework.web.context.request.NativeWebRequest;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.method.support.HandlerMethodArgumentResolver;
//import org.springframework.web.method.support.ModelAndViewContainer;
//
///** 有@LoginUser注解的方法参数，注入当前登录用户
// *
// * @author wuye
// * @date 2018/1/15
// */
//@Component
//public class LoginUserHandlerMethodArgumentResolverSys implements HandlerMethodArgumentResolver {
//
//    public static final String USER_KEY = "LOGIN_USER_KEY_SYS";
//
//    @Autowired
//    private SysUserService userService;
//
//    @Override
//    public boolean supportsParameter(MethodParameter parameter) {
//        return parameter.getParameterType().isAssignableFrom(SysUserEntity.class) && parameter.hasParameterAnnotation(LoginUserSys.class);
//    }
//
//    @Override
//    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
//                                  NativeWebRequest request, WebDataBinderFactory factory) throws Exception {
//        //获取用户ID
//        Object object = request.getAttribute(USER_KEY, RequestAttributes.SCOPE_REQUEST);
//        if(object == null){
//            return null;
//        }
//
//        //获取用户信息
//        SysUserEntity user = userService.findById((Long)object);
//
//        return user;
//    }
//}
